package com.ycq.parser.mark;

import com.ycq.parser.EndMark;
import com.ycq.parser.ImageInfo;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.poi.sl.usermodel.PictureData;
import org.apache.poi.xwpf.usermodel.XWPFParagraph;
import org.apache.poi.xwpf.usermodel.XWPFPicture;
import org.apache.poi.xwpf.usermodel.XWPFPictureData;
import org.apache.poi.xwpf.usermodel.XWPFRun;

import java.util.List;

/**
 * 默认结束标志
 *
 * @author ycq
 * @date 2025/9/24 14:26
 */
public class DefaultMark implements EndMark {

    @Override
    public boolean isEnd(String row, XWPFParagraph paragraph) {
        boolean rowIsEmpty = row == null || row.trim().isEmpty();
        return rowIsEmpty && notExistsPics(paragraph);
    }

    private boolean notExistsPics(XWPFParagraph paragraph) {
        List<XWPFRun> runs = paragraph.getRuns();
        if(CollectionUtils.isNotEmpty(runs)){
            for (XWPFRun run : runs) {
                List<XWPFPicture> embeddedPictures = run.getEmbeddedPictures();
                if(CollectionUtils.isNotEmpty(embeddedPictures)){
                    return false;
                }
            }
        }
        return true;
    }
}
